#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int n,a[N],ans,t;
signed main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld",&n);
        if(n<=20)
        {
            ans=0;
            for(int i=1;i<=n;i++)
                scanf("%lld",&a[i]);
            for(int i=0;i<(1<<n);i++)
            {
                int l=0,m=0,vans=0;
                for(int j=0;j<n;j++)
                    if((1<<j)&i)
                    {
                        vans+=(a[j+1]==a[l])*a[j+1];
                        l=j+1;
                    }
                    else
                    {
                        vans+=(a[j+1]==a[m])*a[j+1];
                        m=j+1;
                    }
                ans=max(ans,vans);
            }
            printf("%lld\n",ans);
        }
    }
    return 0;
}
